class CreateClientes < ActiveRecord::Migration
  def self.up
    create_table :clientes do |t|
      t.column :nombre, :string, :null => false
      t.column :ip, :string, :null => false
      t.column :direccion, :string
      t.column :telefono, :string
      t.column :correo, :string
      t.column :celular, :string
      t.column :activo, :boolean, :default => true
      t.column :ancho_id, :integer, :null => false
      t.column :gtw_id, :integer, :null => false
      t.column :acelerador_id, :integer, :null => false
    end

    execute "CREATE INDEX relacion_clientes_anchobs_index ON clientes (ancho_id) "
    execute "ALTER TABLE clientes ADD CONSTRAINT relacion_clientes_anchobs_id_fkey FOREIGN KEY (ancho_id) REFERENCES anchobs(id);"
    
    execute "CREATE INDEX relacion_clientes_gateways_index ON clientes (gtw_id) "
    execute "ALTER TABLE clientes ADD CONSTRAINT relacion_clientes_gateways_id_fkey FOREIGN KEY (gtw_id) REFERENCES gateways(id);"
        
    execute "CREATE INDEX relacion_clientes_acelerador_index ON clientes (acelerador_id) "
    execute "ALTER TABLE clientes ADD CONSTRAINT relacion_clientes_aceleradors_id_fkey FOREIGN KEY (acelerador_id) REFERENCES aceleradors(id);"
  end

  def self.down
    drop_table :clientes
  end
end
